﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FATCASchema.Nodes
{
    public class FATCA_OECDNode : iNode
    {
        public string Name { get; private set; }
        public bool AllowAddChildren { get; private set; }
        public List<iNode> Children { get; private set; }
        public object NodeObject { get; private set; }

        public FATCA_OECDNode(FATCA_OECD nodeObject)
        {
            this.Name = "FATCA_OECD";
            this.NodeObject = nodeObject;
            this.AllowAddChildren = false;
            this.LoadChildren();
        }

        public void LoadChildren()
        {
            if(this.NodeObject == null)
                return;

            var nodeObject = (FATCA_OECD)this.NodeObject;
            this.Children = new List<iNode>();
            this.Children.Add(new MessageSpecNode(nodeObject.MessageSpec));

            foreach (var item in nodeObject.FATCA)
            {
                this.Children.Add(new FATCANode(item));
            }
        }

        public iNode AddFATCA()
        {
            if (this.NodeObject == null)
                return null;

            var nodeObject = (FATCA_OECD)this.NodeObject;
            var fatcaList = nodeObject.FATCA.ToList();
            var newFatcaItem = FATCA_OECD.NewFATCAElement();
            fatcaList.Add(newFatcaItem);

            var fatcaNode = new FATCANode(newFatcaItem);
            this.Children.Add(fatcaNode);

            return fatcaNode;
        }

        public void AddChild()
        { }

        public void LoadPane()
        { }

    }
}
